package com.wechat.login;

import java.io.File;

import com.swak.Constants;
import com.swak.OS;
import com.swak.codec.Digests;
import com.swak.codec.Encodes;
import com.swak.codec.ShortUrls;
import com.swak.config.setting.Settings;
import com.swak.utils.StringUtils;
import com.swak.utils.time.DateTimes;
import com.wechat.Cons;

/**
 * 用户ID
 * 
 * @author 618lf
 */
public class IDGens {

	/**
	 * 生成用户ID：bc_mac_随机
	 * 
	 * @return
	 */
	public static String genUserID() {
		byte[] salt = Digests.generateSalt(8);
		String mac = StringUtils.remove(OS.hardware(), "-");
		try {
			File runtimeFile = Settings.intSettings().getRuntimeFile();
			String file = runtimeFile.getAbsolutePath();
			String path = Encodes.encodeHex(Digests.md5(file.getBytes(), salt));
			String path0 = ShortUrls.encode(path)[0];
			return Cons.User_Pref + mac.toLowerCase() + path0;
		} catch (Exception e) {
		}
		return Cons.User_Pref + mac.toLowerCase() + "cafebabe";
	}

	/**
	 * 生成RoomID：bc_ + mac + 序号@Room
	 * 
	 * @return
	 */
	public static String genRoomID() {
		String mac = StringUtils.remove(OS.hardware(), "-");
		long sequence = DateTimes.nowMilli() - Constants.Fix_Time;
		return Cons.ChatRoom_Pref + mac.toLowerCase() + sequence + Cons.ID_ChatRoom;
	}
}
